<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>通达信F10-战略配售可出借</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">									
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
			width:1000px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>
	</head>
	<body>							
		<div id="towrite" class="fixedBox"></div>			
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>		
		<script>
			var bkcolor = $("body").css("backgroundColor")					
			window.onload = function() {								
				getSource();			
				changeStyle();					
			}
			
			$(function() {
				setInterval(function() {					
					getSource();																	
				},
				500);
			})			
			
			function changeStyle() {
				var obj = document.getElementById("towrite");				
				obj.style.left= "0px"; 				
				obj.style.width= "98%";	
				obj.style.height= "620px";		
				obj.style.fontSize="14px";			
			}								
			
			function NumberTransform(num) { 
				var result = num;
				if(Math.abs(num) > 100000000){
					result = num / 100000000;
					result = result.toFixed(2) + "亿";
				}else if(Math.abs(num) > 10000){
					result = num/10000;
					result = result.toFixed(2) + "万";
				}				   
				return result;  
			};
			
			var gpdm = "";
			var dm = "";
			function getSource() {
				var u = decodeURI(window.location.href);					
				if(u.indexOf("##") > -1){
					var gp = u.split('##');				
					dm = gp[1];
					gpmc = gp[2];					
					//alert(dm);
					dm == gpdm ? ds = 0: ds = 1;					
				}else{
					dm = "600000";
					gpmc = "浦发银行";
				}
				
				if(dm != gpdm){					
					gpdm = dm;
					var div = document.getElementById('towrite');														
					div.innerHTML = "<span style='color:#FFFF00;font-size:16px;margin:0px 0px 5px 10px' >战略配售可出借</span><span style='color:#FF8040; font-size:14px;'>（" + gpdm + "&nbsp;&nbsp;" + gpmc + "）</span>";						
					
					var data = {"Params":[gpdm ,"zlpskcj",""]};										
					var url = "http://static.tdx.com.cn:7615/TQLEX?Entry=CWServ.tdxf10_gg_jyds"
					var res = [];
					$.ajax({
						type: "post",
						url: url,						
						data : JSON.stringify(data),
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,					
						success: function(data) {					
							//alert(JSON.stringify(data))						
							//document.write(JSON.stringify(data.ResultSets[0].Content));	
							var arr = data.ResultSets[0].Content;
							for (i = 0; i < arr.length; i++){
								var aa = arr[i];
								res.push({"交易日期":aa[0],"限售股(股)":NumberTransform(aa[1]),"非限售股(股)":NumberTransform(aa[2]),"可出借股份(股)":NumberTransform(aa[3]),
								"出借余量(股)":NumberTransform(aa[4]),"可出借容量上限(股)":NumberTransform(aa[5]),"可出借股份占非限售%":aa[6],"出借余量占非限售%":aa[7]});	
							}											
						}
					});	
					//document.write(JSON.stringify(res));	
					if(res.length>0){
						var json = res;
						 
						//创建table					
						var table=document.createElement("table");										
						var thead=document.createElement("thead");
						table.appendChild(thead);					
						var tr=document.createElement("tr");
						thead.appendChild(tr);					
										
						for(var key in json[0]){  //表头					
							var th=document.createElement("th");						
							th.innerHTML=key;						
							tr.appendChild(th);						
						}							
						var tbody=document.createElement("tbody");					
						table.appendChild(tbody);
						
						//遍历json
						for(var i = 0; i < json.length; i++){					
							var tr=document.createElement("tr");						
							var p = 1;
							var dm = "";
							var mc = "";
							for(var key in json[i]){ //行元素遍历						
								var td=document.createElement("td");													
								td.innerHTML = json[i][key];						
								tr.appendChild(td);
							}						
							tbody.appendChild(tr);
						}					
						var div = document.getElementById("towrite");									
						div.appendChild(table);
						table.id = "gg";
						//table.style.marginTop = "10px";
						var table=document.getElementsByTagName("table")[0];
					}else{
						div.innerHTML += "<p style='font-size:16px;color:#fff;'>无此项数据</p>";
					}					
				}
			}
		</script>						
	</body>
</html>